#pragma once

#include <iostream>
#include <modbus.h>
#include <errno.h>
#include <iomanip> 

class ModbusDevice{
public:
    modbus_t *ctx_ = nullptr;
    int current_slave_id;
public:
    ModbusDevice(const std::string &port, int baud, char parity, int data_bit, int stop_bit, int slave_id);
    ~ModbusDevice();

    void SetSlaveID(int slave_id);
    void SetResponseTimeout(uint32_t sec,uint32_t usec);

    bool ModbusConnect();

    bool ModbusReadRegisters(int addr, int len, uint16_t *dest);

};